import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';
import type { MakeupArtist } from '../types';

import { requestClient } from '#/api/request';

export namespace MakeupArtistApi {
  /** 化妆师资源信息 */
  export interface MakeupArtist {
    id: number;
    artistCode?: string;
    artistName?: string;
    level: string;
    specialtyStyle: string;
    servicePrice: number;
    rating: number;
    serviceCount: number;
    status: string;
    remark: string;
  }

  /** 化妆服务订单 */
  export interface MakeupServiceOrder {
    id: number;
    orderId: string;
    artistCode: string;
    artistName: string;
    customerId: string;
    customerName: string;
    serviceTime: string;
    serviceAddress: string;
    serviceAmount: number;
    paidAmount: number;
    status: string;
    rating?: number;
    comment?: string;
    createTime: string;
  }
}

const resourceBaseUrl = '/wedding/resource/makeup-artist';
// ==================== 标准CRUD接口 (/wedding/makeup-artist) ====================

/** 查询化妆师资源分页 */
export function getMakeupArtistPage(params: PageParam) {
  return requestClient.get<PageResult<MakeupArtist>>(resourceBaseUrl+'/page', { params });
}

/** 查询化妆师资源详情 */
export function getMakeupArtist(id: number) {
  return requestClient.get<MakeupArtist>(resourceBaseUrl+`/get?id=${id}`);
}

/** 新增化妆师资源 */
export function createMakeupArtist(data: MakeupArtist) {
  return requestClient.post(resourceBaseUrl+'/create', data);
}

/** 修改化妆师资源 */
export function updateMakeupArtist(data: MakeupArtist) {
  return requestClient.put(resourceBaseUrl+'/update', data);
}

/** 删除化妆师资源 */
export function deleteMakeupArtist(id: number) {
  return requestClient.delete(resourceBaseUrl+`/delete?id=${id}`);
}

/** 导出化妆师资源 */
export function exportMakeupArtist(params: any) {
  return requestClient.download(resourceBaseUrl+'/export-excel', { params });
}

// ==================== 扩展功能接口 (/wedding/resource/makeup-artist) ====================


/** 获取化妆师服务订单 */
export function getArtistOrders(artistCode: string) {
  return requestClient.get<MakeupArtistApi.MakeupServiceOrder[]>(
    `${resourceBaseUrl}/orders`,
    { params: { artistCode } },
  );
}

/** 获取化妆师评价列表 */
export function getArtistRatings(artistCode: string, params?: { pageNo?: number; pageSize?: number }) {
  return requestClient.get<PageResult<MakeupArtistApi.MakeupServiceOrder>>(
    `${resourceBaseUrl}/ratings`,
    { params: { artistCode, ...params } },
  );
}

/** 获取化妆师统计数据 */
export function getArtistStatistics(artistCode: string) {
  return requestClient.get<{
    totalOrders: number;
    completedOrders: number;
    averageRating: number;
    totalRevenue: number;
  }>(`${resourceBaseUrl}/statistics`, {
    params: { artistCode },
  });
}

/** 上传化妆师头像 */
export function uploadArtistAvatar(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post<string>(
    `${resourceBaseUrl}/upload-avatar`,
    formData,
    {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    },
  );
}

/** 上传作品集图片 */
export function uploadWorkSample(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post<string>(
    `${resourceBaseUrl}/upload-work-sample`,
    formData,
    {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    },
  );
}


